/**
 * command like network method
 */
import { NativeModules } from 'react-native';

export const request = options => {
    return new Promise(resolve => {
        NativeModules.RNManager.commandExtension(
            {
                //调用iOS的方法，第一个参数是字典
                name: 'fetch',
                params: {
                    method: options.method, //默认GET。参数只能是：GET，POST，OPTIONS，HEAD，PUT，PATCH，DELETE，TRACE，CONNECT
                    url: options.url, //请求的URL
                    type: 'json' //响应类型，默认text。参数只能是：json，text
                }
            },
            data => {
                resolve({ data, statusCode: 200 });
            }
        );
    });
};

export default request;
